<?php
	class Goods_shixun extends MY_controller{

		function __construct(){
			parent::__construct();
		}

		function index(){
			$data = json_decode(file_get_contents("http://123.206.137.187:804/HandlerData.ashx?action=GetZhangtaoInfo"),true);
			$this->smarty->assign("shixun", $data['rows']);
			$this->smarty->assign("action", '实训');
			$this->smarty->display("goods_shixun/list.html");
		}

		function add($sx_id = 0){
			$post_data = $this->input->post();
			if($post_data){
				$num = intval($post_data['num']);
				if($post_data['num'] > 0){
					$post_data['data_id'] = $sx_id;
					$post_data['data_type'] = 5;
					$post_data['type'] = 1;
					$post_data['add_time'] = time();
					$this->db->insert('o2o_school_order_records',$post_data);
					$record_id = $this->db->insert_id();

					$time = time();
					for ($i=0; $i < $num; $i++) { 
						$yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
						$code = $yCode[rand(0, 9)] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
						$code_data[] = array("school_id" => $post_data['school_id'], "sx_id" => $sx_id, "add_time" => $time, "code" => "DV" . $code, "record_id" => $record_id);
					}
					$insert_result = $this->db->insert_batch("o2o_school_system_shixun_codes", $code_data);
				}else{
					show_error($_SERVER['HTTP_REFERER'], "激活码数量不能为空！");exit;
				}
				/*if($insert_result){
					$post_data['data_id'] = $subject_id;
					$post_data['type'] = 1;
					$post_data['add_time'] = time();
					$result = $this->db->insert('o2o_school_order_records',$post_data);
				}*/
				if($record_id > 0){
					show_message($_SERVER['HTTP_REFERER'],'添加成功');
				}else{
					show_message($_SERVER['HTTP_REFERER'],'操作失败');
				}
			}else{
				$this->load->model("Schools");
				$school_data = $this->Schools->get_school_list();
				$school_list = $school_data;
				$this->smarty->assign("school", $school_list);
				$this->smarty->assign("action", '授权');
				$this->smarty->display("goods_topic/save.html");
			}
		}
	}